//
//  HKContactManager.h
//  HKAddressBookManager
//
//  Created by 胡锦涛 on 2018/12/27.
//  Copyright © 2018 胡锦涛. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Contacts/Contacts.h>

NS_ASSUME_NONNULL_BEGIN
@class HKPerson, HKSectionPerson;

/** 通讯录变更回调（未分组的通讯录） */
typedef void (^HKContactChangeHandler) (void);

@interface HKContactManager : NSObject

@property (nonatomic, copy) NSMutableArray *mdns;
+ (instancetype)sharedInstance;
///通讯录变更回调
@property (nonatomic, copy) HKContactChangeHandler contactChangeHandler;

///请求授权
- (BOOL)authorizationStatusAuthorized;
- (void)requestAddressBookAuthorization:(void (^) (BOOL authorization))completion;
- (void)showAlert;

///选择联系人
- (void)selectContactAtController:(UIViewController *)controller
                      complection:(void (^)(NSString *name, NSString *phone))completcion;
///创建新联系人
///创建新联系人-手机号
- (void)createNewContactWithPhoneNum:(NSString *)phoneNum controller:(UIViewController *)controller;
///创建新联系人-手机号-昵称-用户头像
- (void)createNewContactWithPhoneNum:(NSString *)phoneNum withUserName:(NSString *)userName withUserIconName:(NSString *)userIcon complection:(void (^)( CNContact *))completcion;

///添加到现有联系人
///添加到现有联系人-手机号
- (void)addToExistingContactsWithPhoneNum:(NSString *)phoneNum controller:(UIViewController *)controller;
///添加到现有联系人-手机号-昵称-用户头像
- (void)setExistingContactsWithUserIconName:(NSString*)userIcon userName:(NSString *)userName withContact:(CNContact *)contact complection:(void (^)( CNContact *))completcion;

///删除联系人
- (void)deleteContactsWithContact:(CNMutableContact *)contact complection:(void (^)( CNContact *))completcion;

///获取联系人列表（未分组的通讯录）
- (void)accessContactsComplection:(void (^)(BOOL succeed, NSArray <HKPerson *> *contacts))completcion;

///获取联系人列表（已分组的通讯录）
- (void)accessSectionContactsComplection:(void (^)(BOOL succeed, NSArray <HKSectionPerson *> *contacts, NSArray <NSString *> *keys))completcion;

///通讯录所有手机号未分组
- (void)getPhoneNums:(void (^)(NSMutableArray *nums))completcion;

///通讯录所有手机号+名字(分组)
- (void)getNameAndNums:(void (^)(NSMutableArray *params))completcion;

///通讯录所有手机号+唯一标识(分组)
- (void)getNumsAndUniqueIdentifier:(void (^)(NSMutableArray *params))completcion;
@end

NS_ASSUME_NONNULL_END
